#include "hal_rocker.h"
#include "adc.h"

int fluctuate = 30;
int no = 3400;
int up = 2700;
int left = 2860;
int down = 2440;
int right = 2000;
int center = 2940;

void rocker_init(void)
{


}



void read_rocker(void)
{
	int i;
	int count = 1;
	int voltval = 0;
	int adc_count = 0;
	for(i=0;i<count;i++)
	{
		HAL_ADC_Start(&hadc1);
		HAL_ADC_PollForConversion(&hadc1,0xffff);
		adc_count+=HAL_ADC_GetValue(&hadc1);
		HAL_ADC_Stop(&hadc1);
	}
	
	voltval = adc_count/count;
	//printf(" PA0 value = %1.3fV,bit=%d \r\n", voltval*3.3f/4096, voltval);
	if ( voltval>= no-fluctuate)
	{
			//print("no\r\n");
	}
	if (voltval>=up-fluctuate && voltval<up+fluctuate)
	{
			printf("up\r\n");
	}
	if (voltval>=left-fluctuate && voltval<left+fluctuate)
	{
			printf("left\r\n");
	}

	if (voltval>=down-fluctuate && voltval< down+fluctuate )
	{
			printf("down\r\n");
	}

	if (voltval>=right-fluctuate && voltval< right+fluctuate)
	{
			printf("right\r\n");
	}
	if (voltval>=center-fluctuate && voltval< center+fluctuate)
	{
			printf("center\r\n");
	}
}